//
//  HomeHeaderView.swift
//  ProjectApp
//
//  Created by 邹琳 on 2019/7/24.
//  Copyright © 2019 邹琳. All rights reserved.
//

import UIKit
import ZYBannerView

class HomeHeaderView: UIView {

    @IBOutlet weak var stackView: UIStackView!
    let banner:ZYBannerView = {
        let temp = ZYBannerView(frame: CGRect.zero)
        temp.layer.cornerRadius = 10
        temp.layer.masksToBounds = true
        return temp
    }()
    override func awakeFromNib() {
        super.awakeFromNib()
        let arr = ["美人阁全麦妹…","钮祜禄·态姐","靓丽无限"]
        let arr2 = ["36人在线","27人在线","40人在线"]
        
        for (idx, val) in arr.enumerated() {
            guard let temp = HomeHotView.createFromNib() else {
                return 
            }
            temp.labelName.text = val
            temp.labelNumber.text = "∙" + arr2[idx]
            self.stackView.addArrangedSubview(temp)
        }
        
        self.addSubview(self.banner)
        
        self.banner.snp.makeConstraints { (make) in
            make.left.equalTo(15)
            make.top.equalTo(19)
            make.right.equalTo(-15)
            make.height.equalTo(130)
        }
        
        self.banner.dataSource = self
    }
    
    static func createFromNib() -> HomeHeaderView? {
        let topLevelArray = Bundle.main.loadNibNamed("HomeHeaderView", owner: self, options: nil)
        let views = Array(topLevelArray!).filter { $0 is HomeHeaderView }
        return views.last as? HomeHeaderView
    }
}

extension HomeHeaderView: ZYBannerViewDataSource {
    func banner(_ banner: ZYBannerView!, viewForItemAt index: Int) -> UIView! {
        let imageView = UIImageView(image: UIImage(named: "\(index+1)")!)
        return imageView
    }
    
    func numberOfItems(inBanner banner: ZYBannerView!) -> Int {
        return 3
    }
}
